const chalk = require('chalk')
const log = console.log
var loanM1 = 10986.11,
    loanM1fate = 0.00045

var loanM2 = 91043.92,
    loanM2fate = 0.0003

var mySalary = 4000 + 2000,
    month = 30

var lixi = loanM1 * loanM1fate * month + loanM2 * loanM2fate * month
// var huan1total = loanM1 * loanM1fate * month
// var huan2total = loanM2 + loanM2 * loanM2fate * month
// var huan2lixi = loanM2 * loanM2fate * month
// var totalHByMonth = huan2total
var extraMoney = 0
var totalMonth = 0
var totalH = 0
function myPlan(totalHByMonth, lixi) {


    if (totalHByMonth > 0) {
        console.log(chalk.red(`/************第${totalMonth + 1}月************/`))
        console.log(chalk.blue(`需要还的本金本息剩余为：${totalHByMonth}`))
        console.log(chalk.green(`第${totalMonth + 1}月所还利息为：${lixi}`))
        extraMoney += lixi
        totalMonth++

        totalHByMonth = totalHByMonth + lixi - mySalary
        if (totalHByMonth < 0) {
            lixi = (totalHByMonth + mySalary) * loanM2fate * month
            extraMoney += lixi
            totalMonth++
        } else {
            lixi = totalHByMonth * loanM2fate * month
        }
        myPlan(totalHByMonth, lixi)
    } else {
        console.log(chalk.yellow(`/************第${totalMonth + 1}月************/`))
        console.log(chalk.yellow(`需要本金本息剩余为：${totalHByMonth}`))
        console.log(chalk.yellow(`第${totalMonth + 1}月所还利息为：${lixi}`))
        console.log(chalk.yellow('**********************************'))
        console.log(chalk.yellow('终于还完啦，恭喜哈哈哈哈哈O(∩_∩)O'))
        console.log(chalk.yellow('****************总计******************'))
        console.log(chalk.yellow('还完产生的总利息：', extraMoney))
        console.log(chalk.yellow('还完总共需要的时间（月）：', totalMonth))
    }
    
    



}
myPlan(loanM1+loanM2, lixi)